/*
 * @Author: Rays77
 * @Date: 2022-10-13 15:55:47
 * @LastEditors: Rays77
 * @LastEditTime: 2022-10-24 14:52:39
 * @Description:
 * @FilePath: \shop-admin\src\store\menuStore\index.ts
 */
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { User } from '@/api/interface/index'

export const useMenuStore = defineStore('menuStore', () => {
  // state
  const isCollapse = ref(false)
  const user = ref(null as ({ token: string } & User.IUserInfo) | null)
  const menus = ref([] as User.IMenu[])

  // getter
  // const getOptions = computed(() => options);

  // action
  /**
   * @description
   * @param {boolean} payload
   */
  function setIsCollapse(payload: boolean) {
    isCollapse.value = payload
  }

  function setUser(payload: ({ token: string } & User.IUserInfo) | null) {
    user.value = payload
  }

  function setMenus(payload: User.IMenu[]) {
    menus.value = payload
  }

  return {
    isCollapse,
    user,
    menus,
    setIsCollapse,
    setUser,
    setMenus,
  }
})
